package com.kaifamiao.vector;

import java.util.List;
import java.util.Stack;

public class StackTest {

	public static void main(String[] args) {
		
		Stack<String> stack = new Stack<>();
		
		System.out.println( stack.empty() ); // 判断栈是否为空
		
		// 将 stack 当作集合使用
		stack.addAll( List.of( "张三丰" , "殷天正" ) );
		// 以字符串形式的右侧为栈顶
		System.out.println( stack );
		
		System.out.println( stack.empty() ); // 判断栈是否为空
		
		stack.push( "张翠山" ); // 将元素压入栈顶
		System.out.println( stack );
		
		stack.push( "殷素素" ); // 将元素压入栈顶
		System.out.println( stack );
		
		stack.push( "张无忌" ); // 将元素压入栈顶
		System.out.println( stack );
		
		stack.push( "敏敏特穆尔" ); // 将元素压入栈顶
		System.out.println( stack );
		
		String top = stack.peek(); // 检查栈顶元素(但不移除)
		System.out.println( top );
		System.out.println( stack );
		
		top = stack.pop(); // 弹出栈顶元素(并返回该元素)
		System.out.println( top );
		System.out.println( stack );
		
		int index = stack.search( "张无忌" ); // 返回对象在栈中的位置(以1为基数)
		System.out.println( index );
		
		// 将 stack 当作集合使用
		stack.clear();
		System.out.println( stack );
		
		// System.out.println( stack.peek() ); // 若栈为空则抛出EmptyStackException
		// System.out.println( stack.pop() ); // 若栈为空则抛出EmptyStackException
		index = stack.search( "张无忌" ); //  若栈为空或未找到元素则返回 -1
		System.out.println( index );
		
	}

}
